home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / amigalib / getenv.c next >
Encoding:
C/C++ Source or Header  |  1995-03-19  |  497 b   |  30 lines

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <proto/dos.h>
  4.  
  5. char *
  6. getenv(const char *s)
  7. {
  8.   static char buf[80], *buf2, *env;
  9.   int len, err;
  10.  
  11.   len = GetVar(s, buf, sizeof(buf), GVF_GLOBAL_ONLY);
  12.  
  13.   if (len < 0) {
  14.     env = NULL;
  15.   }else{
  16.     err = IoErr();
  17.     if (err == 0) {
  18.       buf[len] = 0;
  19.       env = strdup(buf);
  20.     }else{
  21.       len = err;
  22.       buf2 = malloc(len+1);
  23.       GetVar(s, buf2, len+1, GVF_GLOBAL_ONLY);
  24.       buf2[len] = 0;
  25.       env = buf2;
  26.     }
  27.   }
  28.   return env;
  29. }
  30.